package it.tcon.xbeedriver;

//Inserito XTT in branch

import it.tcon.xbeedriver.services.Switch;

import org.apache.log4j.Logger;

import com.rapplogic.xbee.api.XBeeAddress16;
import com.rapplogic.xbee.api.XBeeAddress64;
import com.rapplogic.xbee.api.XBeeException;
import com.rapplogic.xbee.util.ByteUtils;

public class Test3 {
	static XBeeCom xbeecom;
	static Logger logger = Logger.getLogger(Test3.class);
	public static void main(String args[]) throws InterruptedException{
		xbeecom = new XBeeCom();
		
		if(!xbeecom.xbeeConnect("/dev/ttyUSB0", 9600)){
			logger.error("Could not connect to XBee device");
			System.exit(1);
		}
		logger.debug("Connected");
		Thread.currentThread().sleep(6000);
		xbeecom.xbeeReceiver();
		
		xbeecom.xbeeDiscover();
		
		XBeeAddress16 addr16 = XBeeAddress16.ZNET_BROADCAST;
		XBeeAddress64 addr64_2 = new XBeeAddress64(0,0x13,0xa2,0,0x40,0x0a,0x33,0x7e);
		XBeeAddress64 addr64 = new XBeeAddress64(0,0x13,0xa2,0,0x40,0x0a,0x33,0x98);
		
		
		
		/*try {
		
			xbeecom.xbeeSend("MY", "RAT", addr64_2,addr16);
			
			xbeecom.xbeeSend("SH", "RAT" ,addr64_2,addr16);
			xbeecom.xbeeSend("SL", "RAT", addr64_2,addr16);
			xbeecom.xbeeSend("NI", "RAT", addr64_2,addr16);
			xbeecom.xbeeSend("DD", "RAT" ,addr64_2,addr16);
			xbeecom.xbeeSend("CH", "RAT", addr64_2,addr16);
			xbeecom.xbeeSend("BH", "RAT" ,addr64_2,addr16);
			xbeecom.xbeeSend("SC", "RAT", addr64_2,addr16);
			xbeecom.xbeeSend("SD", "RAT", addr64_2,addr16);
			xbeecom.xbeeSend("NJ", "RAT", addr64_2,addr16);
			xbeecom.xbeeSend("AR", "RAT", addr64_2,addr16);
			xbeecom.xbeeSend("PL", "RAT", addr64_2,addr16);
			xbeecom.xbeeSend("PM", "RAT" ,addr64_2,addr16);
			xbeecom.xbeeSend("AP", "RAT" ,addr64_2,addr16);
			xbeecom.xbeeSend("AO", "RAT" ,addr64_2,addr16);
			
			xbeecom.xbeeSend("BD", "RAT" ,addr64_2,addr16);
			
			xbeecom.xbeeSend("VR", "RAT" ,addr64_2,addr16);
			xbeecom.xbeeSend("HV", "RAT" ,addr64_2,addr16);
			
	
		//xbeecom.xbeeSend("MY", "RAT",addr64,addr16);

		xbeecom.xbeeSend("SH", "RAT", addr64,addr16);
		xbeecom.xbeeSend("SL", "RAT", addr64,addr16);
		xbeecom.xbeeSend("NI", "RAT", addr64,addr16);
		xbeecom.xbeeSend("DD", "RAT", addr64,addr16);
		xbeecom.xbeeSend("CH", "RAT", addr64,addr16);
		xbeecom.xbeeSend("ID", "RAT", addr64,addr16);
		xbeecom.xbeeSend("BH", "RAT", addr64,addr16);
		xbeecom.xbeeSend("SC", "RAT", addr64,addr16);
		xbeecom.xbeeSend("SD", "RAT", addr64,addr16);
		xbeecom.xbeeSend("NJ", "RAT", addr64,addr16);
		xbeecom.xbeeSend("AR", "RAT", addr64,addr16);
		xbeecom.xbeeSend("PL", "RAT", addr64,addr16);
		xbeecom.xbeeSend("PM", "RAT", addr64,addr16);
		xbeecom.xbeeSend("AP", "RAT", addr64,addr16);
		xbeecom.xbeeSend("AO", "RAT", addr64,addr16);
		xbeecom.xbeeSend("BD", "RAT", addr64,addr16);
		xbeecom.xbeeSend("VR", "RAT", addr64,addr16);
		xbeecom.xbeeSend("HV", "RAT", addr64,addr16);

		
		
		

		
		
		Thread.currentThread().sleep(6000);
		
		xbeecom.saveNodeList();
		} catch (XBeeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		Thread.currentThread().sleep(5000);
		/*XBeeNodeService service0 = new XBeeNodeService("Light 1");
		XBeeNodeService service1 = new XBeeNodeService("Light 2");
		XBeeNodeService service2 = new XBeeNodeService("Temp 1");
		XBeeNodeService service3 = new XBeeNodeService("Acc.X");
		XBeeNodeService service4 = new XBeeNodeService("Acc.Y");
		try {
			xbeecom.setService("0x00 0x13 0xa2 0x00 0x40 0x0a 0x33 0x98", service0);
			xbeecom.setService("0x00 0x13 0xa2 0x00 0x40 0x0a 0x33 0x98", service1);
			xbeecom.setService("0x00 0x13 0xa2 0x00 0x40 0x0a 0x33 0x98", service2);
			xbeecom.setService("0x00 0x13 0xa2 0x00 0x40 0x0a 0x33 0x98", service3);
			xbeecom.setService("0x00 0x13 0xa2 0x00 0x40 0x0a 0x33 0x98", service4);
		} catch (XBeeNodeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
		Switch s = new Switch();
		
		try {
			xbeecom.setService("0x00 0x13 0xa2 0x00 0x40 0x0a 0x33 0x98", s);
			
			logger.debug("Service :" + s.getServiceName());
			logger.debug(" data: "+ xbeecom.getService("0x00 0x13 0xa2 0x00 0x40 0x0a 0x33 0x98", s.getServiceName()));
		} catch (XBeeNodeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		xbeecom.saveNodeList();
			
	}
}
